package com.Mt.Serviceimpl;

import com.Mt.Service.Mt_UserService;
import com.Mt.mapper.MT_UserMapper;
import com.Mt.pojo.Mt_User;
import com.Mt.pojo.Page;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class Mt_UserServiceimpl implements Mt_UserService {

    @Autowired
    private MT_UserMapper mt_UserMapper;
    /**
     * 通过openID查询用户是否登录/注册
     *
     * @param userId
     * @return
     */
    @Override
    public Mt_User queryByopenId(String userId){
        return mt_UserMapper.queryByopenId(userId);
    }

    /**
     * 添加一个新的用户
     *
     * @param mt_User
     * @return
     */
    @Override
    public int AddUser(Mt_User mt_User) {
        return  mt_UserMapper.AddUser(mt_User);
    }

    @Override
    public int upd(Mt_User mt_User) {
        return mt_UserMapper.upd(mt_User);
    }

    @Override
    public int add(Mt_User mt_user) {
        return mt_UserMapper.add(mt_user);
    }

    //修改全部数据
    @Override
    public int update(Mt_User mt_user) {
        return this.mt_UserMapper.update(mt_user);
    }
    //查询全部数据及根据Id，手机号，名字,查询
    @Override
    public List selAll(Mt_User mt_user) {
        return mt_UserMapper.selAll(mt_user);
    }

    //分页
    @Override
    public Page<Mt_User> page(int pageIndex) {
        int size = 3;
        int count = mt_UserMapper.count();
        int pageEnd = count % size == 0 ? count / size : count / size + 1;
        return new Page<Mt_User>(count, pageEnd, mt_UserMapper.page((pageIndex - 1) * size, size));
    }
}
